package com.xcdh.trading.controller;

import com.xcdh.domain.vo.R;
import com.xcdh.trading.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CompletableFuture;

@RestController
@RequestMapping("/sync/all")
public class SyncTrDataController {
    @Autowired
    private HotMoneyTrcService hotMoneyTrcService ;

    @Autowired
    private CapitalFlowService capitalFlowService ;

    @Autowired
    private SectorCapitalFlowService sectorCapitalFlowService ;

    @Autowired
    private IndustryCapitalFlowService industryCapitalFlowService ;

    @Autowired
    private DailyIndicatorsService dailyIndicatorsService ;

    @Autowired
    private StockBiddingService stockBiddingService ;

    @Autowired
    private DayTransactionDataService dayTransactionDataService ;


    @PostMapping("/syncAllTrData/{tradeDate}")
    public R syncAllTrData(@PathVariable String tradeDate){
        CompletableFuture.runAsync(()->{
            sectorCapitalFlowService.syncSectorCapitalFlow(tradeDate);
            industryCapitalFlowService.syncIndustryCapitalFlow(tradeDate);
            hotMoneyTrcService.syncHotMoneyTrc(tradeDate);
            stockBiddingService.syncDayBidding(tradeDate);
        }) ;
        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> {
            capitalFlowService.syncCapitalFlow(tradeDate);
            dailyIndicatorsService.syncDailyIndicators(tradeDate);
            dayTransactionDataService.syncTransactionData(tradeDate);
            dayTransactionDataService.countTransactionData(tradeDate) ;
            hotMoneyTrcService.updateHotMoneyTrc(tradeDate);
            return 0;
        });
        CompletableFuture.allOf(future).join() ;

        return R.ok() ;
    }
}
